<template>
  <div class="user-center-container">
    <el-upload
      class="avatar-uploader"
      :action="uploadUrl"
      :show-file-list="false"
      :on-success="handleAvatarSuccess">
      <img v-if="userInfo.avatar" :src="userInfo.avatar" class="avatar">
      <i v-else class="el-icon-plus avatar-uploader-icon"></i>
    </el-upload>
    
    <el-form :model="userInfo" label-width="100px">
      <el-form-item label="电子邮箱" prop="email">
        <el-input v-model="userInfo.email"></el-input>
      </el-form-item>
      <el-form-item label="联系电话">
        <el-input v-model="userInfo.tel" :disabled="!isEditing"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="handleSubmit">{{ isEditing ? '保存修改' : '编辑信息' }}</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  computed: {
    ...mapState(['avatar', 'email', 'phone'])
  },
  methods: {
    handleAvatarSuccess(res, file) {
      this.$store.commit('UPDATE_PROFILE', { 
        avatar: URL.createObjectURL(file.raw)
      });
    }
  }
}
</script>

<style scoped>
.user-center {
  max-width: 800px;
  margin: 30px auto;
  padding: 30px;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.1);
}

.el-form-item {
  margin-bottom: 25px;
}

.el-input {
  width: 300px;
}
</style>